﻿@using wne.models
@model List<wne.models.GroupSmallModel>
@{
    ViewBag.Title = "AllGroups";
}
@functions
{

    private string IsSelected(int q, int ths)
    {
        return q == ths ? "selected=select" : "";
    }

    private string YesNo(bool val)
    {
        return val ? "Да" : "Нет";
    }

    private string FieldTypeToString(FieldTypeEnum e)
    {
        switch (e)
        {
            case FieldTypeEnum.Bool:
                return "Да/нет";
            case FieldTypeEnum.Date:
                return "Дата";
            case FieldTypeEnum.ManyOf:
                return "Несколько из";
            case FieldTypeEnum.Numeric:
                return "Число";
            case FieldTypeEnum.OneOf:
                return "Одно из";
            case FieldTypeEnum.String:
                return "Строка";
        }
        return "";
    }

    private string GetMarginLeftForGroup(int level)
    {
        level = level * 20;
        return "margin-left: "+level+"px;";
    }

}

<script>    @*раскртыие/закрытие вложенных блоков*@
    function openBlock(e)
    {
        var curr = $(event.target).parent().parent();
        curr.children('.group-open-block').slideToggle("normal");
    }
    function changeDLL()
    {
        $("#search-block-form_and_sort").submit();
    }

    $(document).ready(function() {
        var AllLi = $(".group-block > li");
        for (var i = 0; i < AllLi.length; i++) {
            var currLi = $(AllLi[i]);
            var level = currLi.attr('level');
            currLi.css('margin-left', level * 20 + 'px');
            currLi.css('width', (parseInt(currLi.css('width')) - level * 20) + 'px');
            //currLi.find('.name').css('width', (parseInt(currLi.find('.name')) - level * 20) + 'px');
        }
    });
</script>

@*<link href="/Content/user_groups.css" rel="stylesheet" /> *@@*Не нужны, но пусть пока висят*@
<script src="/Scripts/Group.js"></script>
<div class="modalContent" id="addGroup">
    <form action="/Admin/AddGroup" method="post">
        <input type="text" class="input-medium" placeholder="Имя группы" required name="name"/>
        <input type="submit" class="btn" value="Добавить группу"/>
    </form>
</div>
<div class="hero-unit" style="padding: 14px 10px 14px 20px; margin-left: 2px;">
    <form action="/Admin/AllGroups" class="form-search" method="post" id="search-block-form_and_sort">@*search*@

        <h2>Группы пользователей</h2>

        <div class="row-fluid">
            <div class="span3" style="padding-top: 40px; text-align: center;">
                <a class="btn btn-primary " onclick="showModal('addGroup')">Создать группу &raquo; </a>
            </div>
            <div class="offset1 span4" style="padding-top: 40px;">
                @*<h6>Параметры вывода групп</h6>*@
                <select name="OrderNum" id="OrderNum" size="1" class="span12" onchange="changeDLL()">
                    <option value="2" @IsSelected(2, ViewBag.OrderNum)>Сортировать по алфавиту А-Я</option>
                    <option value="1" @IsSelected(1, ViewBag.OrderNum)>Сортировать по алфавиту Я-А</option>
                    <option value="4" @IsSelected(4, ViewBag.OrderNum)>Сортировать по возрастанию</option>
                    <option value="3" @IsSelected(3, ViewBag.OrderNum)>Сортировать по убыванию</option>
                </select>
            </div>
            <div class="offset1 span3" style="padding-top: 40px;">
                <div class="input-append">
                    <input type="text" class="span9 input-medium search-query" name="SearchString" value="@ViewBag.SearchString" maxlength="128" placeholder="Поиск по имени">
                    <button type="submit" class="btn" onclick="changeDLL();"><i class="icon-search" onclick="changeDLL();"></i></button>
                    <div onclick="$('#search-block-form_and_sort').submit();"></div>
                </div>
            </div>
        </div>
    </form>
</div>


@*<div class="wraper">
    
    <a href="javascript:void(0)" onclick="showModal('addGroup')" class="inline-block w30">Добавить группу</a>
    <select name="SortOrder" class="relative inline-block" size="1" onchange="changeDLL()">
            
        <option value="1" @IsSelected(1, ViewBag.OrderNum)>Сортировать по алфавиту А-Я</option>
        <option value="2" @IsSelected(2, ViewBag.OrderNum)>Сортировать по алфавиту Я-А</option>
        <option value="3" @IsSelected(3, ViewBag.OrderNum)>Сортировать по возрастанию</option>
        <option value="4" @IsSelected(4, ViewBag.OrderNum)>Сортировать по убыванию</option>
    </select>   
</div>*@
    <div class="wraper clearfix">
        @*<div class="paging fleft">
            <a href="javascript:void(0);" class="next"><< Предыдущая</a>
            <div class="btn"><a href="javascript:void(0);">1</a></div>
            <div class="btn"><a href="javascript:void(0);">1</a></div>
            <div class="btn"><a href="javascript:void(0);">1</a></div>
            <a href="javascript:void(0);" class="next">>> Следующая</a>
        </div>
        <div class="fright">
            Колличество групп на странице:<br />
            <input type="radio" name="Pageamount" value="3" checked="checked" />
            3
            <input type="radio" name="Pageamount" value="10" />
            10
            <input type="radio" name="Pageamount" value="30" />
            30
        </div>*@
    </div>
    

@*<ul class="group-block">
    @foreach (var group in Model)
    {
        <li level="@group.Level" class="clearfix">
            <div class="wraper clearfix">
                <a href="/Admin/EditGroup?id=@group.Id" class="name">@group.Name</a>
                <span>@group.Count участников</span>
                <a class="openLink" onclick="openBlock(event)" href="javascript:void(0)">Раскрыть блок</a>
                <a href="javascript:void(0)" onclick="deleteGroup(@group.Id)" class="del"></a>
            </div>
            <ul class="group-open-block" style="display: none;">
                <li><span>Имя поля</span><span>Тип поля</span><span>Обязательное-ли</span><span>Можно редактировать</span></li>
                @foreach (var q in group.Fields)
                {
                    <li><span>@q.Name</span><span>@FieldTypeToString(q.Type)</span><span>@YesNo(q.Mandatory)</span><span>@YesNo(q.UserCanEdit)</span></li>
                }
            </ul>
        </li>
    }
</ul>*@

<style>
     .my-hover-css-class :hover {
         background-color: #e3e6e7;
     }

</style>
<div class="accordion" id="accordion2">
    @foreach (var group in Model)
    {
        <div class="accordion-group" id="groupId_@group.Id"style="margin: 10px 0; @GetMarginLeftForGroup(group.Level) ">
            <div class="accordion-heading my-hover-css-class">
                <span class="accordion-toggle" data-toggle="collapse" href="#@group.Id">
                    <a href="/Admin/EditGroup?id=@group.Id">@group.Name</a>
                    <span style="margin-left: 100px;">@group.Count участников</span>
                </span>
            </div>
            <div id="@group.Id" class="accordion-body collapse">
                <a href="/Admin/EditGroup?id=@group.Id" style="margin-left: 15px"><small>Изменить</small></a>
                <span style="margin-left:  150px;" ><i class='icon-remove' onclick="deleteGroup(@group.Id);"></i></span>
                
                <div class="accordion-inner">
                    
                    <table class="table table-striped table-condensed">
                        <tr>
                            <th>Имя поля</th><th>Тип поля</th><th>Обязательность</th><th>Возможность редактировать</th>
                        </tr>
                        @foreach (var q in group.Fields)
                        {
                            <tr>
                                <td>@q.Name</td><td>@FieldTypeToString(q.Type)</td><td>@YesNo(q.Mandatory)</td><td>@YesNo(q.UserCanEdit)</td>
                            </tr>
                        }
                    </table>  
                </div>
            </div>
        </div>
        
    }
</div>

@* <div class="one-block">
  <span class="name">@q.name</span>
  <span class="count">@q.countUser</span>
  <div class="open-block">
  @foreach (var c in q.AllFields)
  {
   <div class="row">
    <span>@c.Name</span>
    <span>@c.Type</span>
   </div>
  }
  </div>
} *@